﻿using BootstrapBlazor.Components;
using BPM.Web.Shared.Data;
using BPM.Web.Shared.Dependencies;
using BPM.Web.Shared.Extensions;
namespace BPM.Web.Shared.Service;

[Scoped(typeof(ISysTimerService))]
public class SysTimerService : BaseService, ISysTimerService
{
    private readonly ITimerClient _timerClient;
    public SysTimerService(ITimerClient timerClient, ToastService toast) : base(toast)
        => _timerClient = timerClient;

    public Task<QueryData<JobOutput>> PageAsync(TimerPageInput input)
        => QueryAsync(_timerClient.PageAsync(input));

    public Task<List<TaskMethodInfo>?> LocalJobListAsync()
        => QueryAsync<List<TaskMethodInfo>>(_timerClient.LocalJobListAsync());

    public Task<bool> AddAsync(JobOutput input)
        => ExecuteAsync(_timerClient.AddAsync(input.Adapt<AddJobInput>()));

    public Task<bool> DeleteAsync(IEnumerable<JobOutput> input)
        => DeleteAsync(input.Adapts<JobOutput, DeleteJobInput>().Select(x => _timerClient.DeleteAsync(x)));

    public Task<bool> EditAsync(JobOutput input)
        => ExecuteAsync(_timerClient.EditAsync(input.Adapt<UpdateJobInput>()));

    public Task<SysTimer?> DetailAsync(JobOutput input)
        => QueryAsync(_timerClient.DetailAsync(input.Adapt<QueryTimerInput>()));

    public Task<bool> StopAsync(JobOutput input)
        => ExecuteAsync(_timerClient.StopAsync(input.Adapt<StopJobInput>()));

    public Task<bool> StartAsync(JobOutput input)
        => ExecuteAsync(_timerClient.StartAsync(input.Adapt<AddJobInput>()));
}

